<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'
import {mRequest} from '@/utils/request'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        id: {
          hidden: true
        },
        boxInfoId: {
          label: '纸箱',
          type: 'list',
          placeholder: '请选择纸箱',
          list: [],
          selectCallback: () => {
            mRequest('boxApi/boxInfoInfo', {id: this.dataForm.boxInfoId}, ({data}) => {
              this.dataFormConfig['boxNumber']['max'] = this.R.pathOr(0, ['boxInfo', 'residueBoxNoCount'], data)
            })
          }
        },
        boxNumber: {
          label: '纸箱数量',
          type: 'number',
          max: 1000000,
          reply: 'boxInfoId'
        },
        dayTime: {
          label: '日期',
          type: 'date',
          placeholder: '请选择日期'
        },
        leaveType:{
          label: '出库类别 ',
          type: 'radio',
          radioBorder: false,
          radioList: [
            {text: '自用', label: 0},
            {text: '客户拉走', label: 1}
          ]
        },
        clientGoAddress:{
          label: '纸箱去向',
          placeholder: '请输入纸箱去向 拉去哪里'
        },
        remark: {
          label: '备注',
          inputType: 'textarea',
          placeholder: '请输入备注'
        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0
      this.initBoxInfoIdList()

      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('boxInfoId', 'boxNumber', 'status'),
        initApi: 'boxApi/boxLeaveInfo',
        saveApi: 'boxApi/saveBoxLeave',
        updateApi: 'boxApi/updateBoxLeave',
        objectName: 'boxLeave'
      })
    }
  }
}
</script>
